﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace SZ.Mech
{
    /// <summary>
    /// 受击反馈
    /// </summary>
    public class CompProperties_InjuryRebound : CompProperties
    {
        public List<ExtraDamage> extraDamages;
        public CompProperties_InjuryRebound()
        {
            this.compClass = typeof(CompInjuryRebound);
        }

    }

    public class CompInjuryRebound : ThingComp
    {

        private CompProperties_InjuryRebound Props => (CompProperties_InjuryRebound)props;

        public override void PostPostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
        {
            base.PostPostApplyDamage(dinfo, totalDamageDealt);
            if (dinfo.Instigator != (Pawn)this.parent)
            {
                if (dinfo.Amount != 0)
                {
                    TakeDamage(dinfo.Instigator);
                }
            }
        }


        public void TakeDamage(Thing hitTarget)//这里可能会导致自举
        {
            if (hitTarget != null)
            {
                foreach (ExtraDamage extraDamage in Props.extraDamages)
                {
                    if (Rand.Chance(extraDamage.chance))
                    {
                        DamageInfo dinfo2 = new DamageInfo(extraDamage.def, extraDamage.amount, extraDamage.AdjustedArmorPenetration(), instigator: this.parent);
                        hitTarget.TakeDamage(dinfo2);

                    }
                }
            }
        }

    }
}
